Check for Xrandr 1.3
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 13 Feb 2009 18:12:57 +0000 (18:12 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 13 Feb 2009 18:12:57 +0000 (18:12 +0000)
       * configure.in: Check for Xrandr 1.3

        * gdk/x11/gdkdisplay-x11.[ch]: Rename have_randr12 to have_randr13
        and set if if we have randr 1.3

        * gdk/x11/gdkscreen-x11.c: Go back to using randr for monitor
        information, if we have XRRGetScreenResourcesCurrent.

svn path=/trunk/; revision=22327

ChangeLog
configure.in
gdk/x11/gdkdisplay-x11.c
gdk/x11/gdkdisplay-x11.h
gdk/x11/gdkscreen-x11.c

index c72ecf02195ec93ad333139a5d7b2b4a5ce5b368..4cc44d81ee3e7db79ce0345c42bcffbdcaf01fd9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-02-13  Matthias Clasen  <mclasen@redhat.com>
+
+       * configure.in: Check for Xrandr 1.3
+
+       * gdk/x11/gdkdisplay-x11.[ch]: Rename have_randr12 to have_randr13
+       and set if if we have randr 1.3
+
+       * gdk/x11/gdkscreen-x11.c: Go back to using randr for monitor
+       information, if we have XRRGetScreenResourcesCurrent.
+:
 2009-02-12  Cody Russell  <bratsche@gnome.org>
 
        Bug 571576 – gdk_pixbuf_save_to_stream() broken
index 859ee3e61aa5d1ea7a51cb3bee0c6887aa7d8e65..833dc5fc755259a4b544d665ba77b7d1b0f19b52 100644 (file)
@@ -1541,7 +1541,7 @@ if test "x$gdktarget" = "xx11"; then
   AM_CONDITIONAL(XINPUT_XFREE, test x$with_xinput = xxfree || test x$with_xinput = xyes)
 
   # Check for the RANDR extension
-  if $PKG_CONFIG --exists "xrandr >= 1.2" ; then
+  if $PKG_CONFIG --exists "xrandr >= 1.2.99" ; then
      AC_DEFINE(HAVE_RANDR, 1, [Have the Xrandr extension library])
 
      X_PACKAGES="$X_PACKAGES xrandr"
index cdab44491006a641e033064e893bb674c4b91fc4..bf54b95b7586deadea2de8900c7e27953e75c8c1 100644 (file)
@@ -184,7 +184,7 @@ gdk_display_open (const gchar *display_name)
   _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
 
   /* RandR must be initialized before we initialize the screens */
-  display_x11->have_randr12 = FALSE;
+  display_x11->have_randr13 = FALSE;
 #ifdef HAVE_RANDR
   if (XRRQueryExtension (display_x11->xdisplay,
                         &display_x11->xrandr_event_base, &ignore))
@@ -193,8 +193,8 @@ gdk_display_open (const gchar *display_name)
       
       XRRQueryVersion (display_x11->xdisplay, &major, &minor);
 
-      if ((major == 1 && minor >= 2) || major > 1)
-         display_x11->have_randr12 = TRUE;
+      if ((major == 1 && minor >= 3) || major > 1)
+         display_x11->have_randr13 = TRUE;
   }
 #endif
   
index ffd04611137594652e1a081d88ca098ce1d52313..0ade8f08355e4a66adf0635cfb189c12d7fcbf35 100644 (file)
@@ -85,7 +85,7 @@ struct _GdkDisplayX11
   gboolean have_xdamage;
   gint xdamage_event_base;
 
-  gboolean have_randr12;
+  gboolean have_randr13;
   gint xrandr_event_base;
 
   /* If the SECURITY extension is in place, whether this client holds 
index bc564f6c8e4e047db9a57e0ba5a5143e4ad03a93..e13c7a61c2553ab69077430033bab686b8448964 100644 (file)
@@ -663,6 +663,81 @@ init_fake_xinerama (GdkScreen *screen)
   return FALSE;
 }
 
+static gboolean
+init_randr13 (GdkScreen *screen)
+{
+#ifdef HAVE_RANDR
+  GdkDisplay *display = gdk_screen_get_display (screen);
+  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
+  Display *dpy = GDK_SCREEN_XDISPLAY (screen);
+  XRRScreenResources *resources;
+  int i;
+  GArray *monitors;
+  gboolean randr12_compat = FALSE;
+
+  if (!display_x11->have_randr13)
+      return FALSE;
+
+  resources = XRRGetScreenResourcesCurrent (screen_x11->xdisplay,
+                                           screen_x11->xroot_window);
+  if (!resources)
+    return FALSE;
+  
+  monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
+                                resources->noutput);
+
+  for (i = 0; i < resources->noutput; ++i)
+    {
+      XRROutputInfo *output =
+       XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
+
+      /* Non RandR1.2 X driver have output name "default" */
+      randr12_compat |= !g_strcmp0(output->name, "default");
+
+      if (output->crtc)
+       {
+         GdkX11Monitor monitor;
+         XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, output->crtc);
+
+         monitor.geometry.x = crtc->x;
+         monitor.geometry.y = crtc->y;
+         monitor.geometry.width = crtc->width;
+         monitor.geometry.height = crtc->height;
+
+         /* FIXME: fill this out properly - need EDID parser */
+         monitor.output = resources->outputs[i];
+         monitor.width_mm = -1;
+         monitor.height_mm = -1;
+         monitor.output_name = NULL;
+         monitor.manufacturer = NULL;
+
+         g_array_append_val (monitors, monitor);
+
+          XRRFreeCrtcInfo (crtc);
+       }
+
+      XRRFreeOutputInfo (output);
+    }
+
+  XRRFreeScreenResources (resources);
+
+  /* non RandR 1.2 X driver doesn't return any usable multihead data */
+  if (randr12_compat)
+    {
+      g_array_free (monitors, TRUE);
+      return FALSE;
+    }
+
+  screen_x11->n_monitors = monitors->len;
+  screen_x11->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE);
+
+  return TRUE;
+#endif
+  
+  return FALSE;
+}
+
 static gboolean
 init_solaris_xinerama (GdkScreen *screen)
 {
@@ -786,14 +861,14 @@ init_multihead (GdkScreen *screen)
    *  3. Solaris Xinerama
    *  4. XFree86/Xorg Xinerama
    *
-   * However, there are performance issues with calling
-   * XRRGetScreenResources() every time an application starts,
-   * so in the RandR case we simply rely on the information being
-   * exported through Xinerama as well.
+   * We use them in that order.
    */
   if (init_fake_xinerama (screen))
     return;
 
+  if (init_randr13 (screen))
+    return;
+
   if (XQueryExtension (GDK_SCREEN_XDISPLAY (screen), "XINERAMA",
                       &opcode, &firstevent, &firsterror))
     {